<meta charset="utf-8">
(#) Package not included in Android

!!! ERROR: Package not included in Android
   This is an error.

Id
:   `InvalidPackage`
Summary
:   Package not included in Android
Note
:   **This issue is disabled by default**; use `--enable InvalidPackage`
Severity
:   Error
Category
:   Correctness
Platform
:   Android
Vendor
:   Android Open Source Project
Feedback
:   https://issuetracker.google.com/issues/new?component=192708
Since
:   Initial
Affects
:   Library bytecode
Editing
:   This check can *not* run live in the IDE editor
Implementation
:   [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/InvalidPackageDetector.java)
Tests
:   [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/InvalidPackageDetectorTest.java)
Copyright Year
:   2012

This check scans through libraries looking for calls to APIs that are
not included in Android.

When you create Android projects, the classpath is set up such that you
can only access classes in the API packages that are included in
Android. However, if you add other projects to your libs/ folder, there
is no guarantee that those .jar files were built with an Android
specific classpath, and in particular, they could be accessing
unsupported APIs such as java.applet.

This check scans through library jars and looks for references to API
packages that are not included in Android and flags these. This is only
an error if your code calls one of the library classes which wind up
referencing the unsupported package.

(##) Example

Here is an example of lint warnings produced by this check:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text
libs/unsupported.jar:Error: Invalid package reference in library; not
included in Android: javax.swing. Referenced from test.pkg.LibraryClass.
[InvalidPackage]
2 errors, 0 warnings
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here are the relevant test files:

`res/layout/layout.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" &gt;

    &lt;!-- Requires API 5 --&gt;

    &lt;QuickContactBadge
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" /&gt;

    &lt;!-- Requires API 11 --&gt;

    &lt;CalendarView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" /&gt;

    &lt;!-- Requires API 14 --&gt;

    &lt;GridLayout
        foo="@android:attr/actionBarSplitStyle"
        bar="@android:color/holo_red_light"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" &gt;

        &lt;Button
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" /&gt;
    &lt;/GridLayout&gt;

&lt;/LinearLayout&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`res/values/themes.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;resources&gt;
    &lt;style name="Theme" parent="android:Theme"/&gt;

    &lt;style name="Theme.Test" parent="android:style/Theme.Light"&gt;
        &lt;item name="android:windowNoTitle"&gt;true&lt;/item&gt;
        &lt;item name="android:windowContentOverlay"&gt;@null&lt;/item&gt;
        &lt;!-- Requires API 14 --&gt;
        &lt;item name="android:windowBackground"&gt;  @android:color/holo_red_light &lt;/item&gt;
    &lt;/style&gt;

    &lt;style name="Theme.Test.Transparent"&gt;
        &lt;item name="android:windowBackground"&gt;@android:color/transparent&lt;/item&gt;
    &lt;/style&gt;

&lt;/resources&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`res/color/colors.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;resources&gt;
    &lt;style name="Theme" parent="android:Theme"/&gt;

    &lt;style name="Theme.Test" parent="android:style/Theme.Light"&gt;
        &lt;item name="android:windowNoTitle"&gt;true&lt;/item&gt;
        &lt;item name="android:windowContentOverlay"&gt;@null&lt;/item&gt;
        &lt;!-- Requires API 14 --&gt;
        &lt;item name="android:windowBackground"&gt;  @android:color/holo_red_light &lt;/item&gt;
    &lt;/style&gt;

    &lt;style name="Theme.Test.Transparent"&gt;
        &lt;item name="android:windowBackground"&gt;@android:color/transparent&lt;/item&gt;
    &lt;/style&gt;

&lt;/resources&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[libs/unsupported.jar](examples/libs/unsupported.jar)

You can also visit the
[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/InvalidPackageDetectorTest.java)
for the unit tests for this check to see additional scenarios.

The above example was automatically extracted from the first unit test
found for this lint check, `InvalidPackageDetector.testUnsupportedJavaLibraryCode`.
To report a problem with this extracted sample, visit
https://issuetracker.google.com/issues/new?component=192708.

(##) Suppressing

You can suppress false positives using one of the following mechanisms:

* Using a special `lint.xml` file in the source tree which turns off
  the check in that folder and any sub folder. A simple file might look
  like this:
  ```xml
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;lint&gt;
      &lt;issue id="InvalidPackage" severity="ignore" /&gt;
  &lt;/lint&gt;
  ```
  Instead of `ignore` you can also change the severity here, for
  example from `error` to `warning`. You can find additional
  documentation on how to filter issues by path, regular expression and
  so on
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html).

* In Gradle projects, using the DSL syntax to configure lint. For
  example, you can use something like
  ```gradle
  lintOptions {
      disable 'InvalidPackage'
  }
  ```
  In Android projects this should be nested inside an `android { }`
  block.

* For manual invocations of `lint`, using the `--ignore` flag:
  ```
  $ lint --ignore InvalidPackage ...`
  ```

* Last, but not least, using baselines, as discussed
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).

<!-- Markdeep: --><style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style><script src="markdeep.min.js" charset="utf-8"></script><script src="https://morgan3d.github.io/markdeep/latest/markdeep.min.js" charset="utf-8"></script><script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script>